﻿using System;
using System.Collections.Generic;
using System.IO;

namespace Abstract2ion
{
	public class DirectoryItem : IDirectoryItem
	{
		private readonly DirectoryInfo _directoryInfo;

		public DirectoryItem(string path)
		{
			_directoryInfo = new DirectoryInfo(path);
		}

		public DirectoryItem(DirectoryInfo directoryInfo)
		{
			if (directoryInfo == null)
			{
				throw new ArgumentNullException("directoryInfo");
			}
			_directoryInfo = directoryInfo;
		}

		public string Name
		{
			get { return _directoryInfo.Name; }
		}

		public string FullName
		{
			get { return _directoryInfo.FullName; }
		}

		public bool Exists
		{
			get { return _directoryInfo.Exists; }
		}

		public IEnumerable<IDirectoryItem> FindDirectories()
		{
			var directories = _directoryInfo.GetDirectories();

			foreach (var directory in directories)
			{
				yield return new DirectoryItem(directory);
			}
		}

		public IEnumerable<IFileItem> FindFiles()
		{
			var files = _directoryInfo.GetFiles();

			foreach (var file in files)
			{
				yield return new FileItem(file);
			}
		}
	}
}